import Handler from "./Handler";
import HttpHandler from "./HttpHandler";
import HttpHelper from "./HttpHelper";
import MatchGameData from "./MatchGameData";
import NativeUtils from "./NativeUtils";
import PageMgr from "./PageMgr";
import PeripheralSystemDataMgr from "./PeripheralSystemDataMgr";
import PlayerDataSys from "./PlayerDataSys";
import { RequestType } from "./RequestType";

class GameService {
    recoSwitch(e, t, a) {
        debugger
        HttpHandler.create(RequestType.Reco_Switch, t, a).setRequestData(e).handleRequest();
    }
    getClockTaskList(e, t) {
        debugger
        HttpHandler.create(RequestType.GetClockTaskList, e, t).handleRequest();
    }
    getClockTaskReward(e, t, a) {
        debugger
        HttpHandler.create(RequestType.SaveClockTask, t, a).setRequestData(e).handleRequest();
    }
    getExtractInfo(e, t) {
        debugger
        HttpHandler.create(RequestType.GetExtractInfo, e, t).handleRequest();
    }
    getExtractCashRecord(e, t) {
        debugger
        HttpHandler.create(RequestType.ExtractCashRecord, e, t).handleRequest();
    }
    getTravelExtractInfo(e, t) {
        debugger
        HttpHandler.create(RequestType.TravelExtractInfo, e, t).handleRequest();
    }
    extractCash(e, t, a) {
        debugger
        HttpHandler.create(RequestType.ExtractCash, t, a).setRequestData(e).handleRequest();
    }
    videoGetGold(e, t) {
        debugger
        HttpHandler.create(RequestType.VideoGetGold, e, t).handleRequest();
    }
    getTravelInfo(e, t) {
        debugger
        HttpHandler.create(RequestType.TravelInfo, e, t).handleRequest();
    }
    getScollMsg(e, t) {
        var d = { "code": 1, "message": "", "data": { "msg_list": [{ "type": 1, "name": "arsen", "image": "https://thirdwx.qlogo.cn/mmopen/vi_32/icZsCPuSZpcZ0e5pNcdj8FW00KHib2ZyVc6I8L4oe0IczqxqHvkc4ib4SKiavnfpHYaucuEA5go0MS0jxBsldUqEKg/132", "extract": 12143 }] } };
        e.runWith(d);
        // HttpHandler.create(RequestType.ScrollMsg, e, t).handleRequest();
    }
    getVideoReward(e, t, a) {
        var d = { "code": 1, "message": "", "data": { cash_balance: 100, ggk: true, reward: 100, red_flag: true } }
        t.runWith(d);
        // HttpHandler.create(RequestType.VideoReward, t, a).setRequestData(e).handleRequest();
    }
    reportOutsideGuideStep(e, t, a) {
        // HttpHandler.create(RequestType.OutSideGuideStep, t, a).setRequestData(e).handleRequest();
        var d = { "code": 1, "message": "", "data": { gold_balance: 100000, reward: 100000 } }
        t.runWith(d);
    }
    matchGameStart(e, t: Handler, a) {
        console.log(11111111);
        cc.assetManager.loadRemote(`https://static.dayclover.com/feie/level_config/${MatchGameData.gameLevel}.json`, (err, asset) => {
            if (!err) {
                try {
                    let json = asset['json'];
                    let copiedJson = JSON.parse(JSON.stringify(json)); // 创建json的深度拷贝
                    if (!copiedJson.code) {
                        copiedJson.guideIndex = copiedJson.guideIndex;
                        copiedJson.is_backend = 0;
                        const t = MatchGameData.propInfo;
                        copiedJson = { "code": 1, "message": "", "data": { "profile": { "LEVEL_CODE": copiedJson, "LEVEL_STEEPS": copiedJson.totalStep, "STARTGUIDE_TYPE": copiedJson.guideIndex, "EVENT_TYPE": 1 }, "game_level": copiedJson.level, "cash_balance": 3214, "gold_balance": 46934,  "ad_flag": false, "full_ad_flag": false, "backend_level_flag": 0 } };
                    }
                    t.runWith(copiedJson);
                } catch (error) {
                    console.log(222222, JSON.stringify(error))
                }

            } else {
                console.log("关卡加载错误", JSON.stringify(err), MatchGameData.gameLevel)
            }
        })
    }
    submitGame(e, t, a) {
        var d = { "code": 1, "message": "", "data": { "cash": 23, "gold": 3014, "cash_balance": 3568, "gold_balance": 55247, "game_level": MatchGameData.gameLevel, "profile": { "LEVEL_CODE": { "map_version": "20230605-01", "level": 21, "totalStep": 23, "mapArr": [[1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]], "middleSquareData": [["O-18", "O-18", "O-18", "O-18", "O-18", "O-18", "O-18", "O-18", "N", "N", "N"], ["M-4", "M-2", "M-4", "M-4", "M-2", "M-3", "M-4", "O-18", "N", "N", "N"], ["M-2", "M-4", "M-1", "M-1", "M-2", "M-4", "M-3", "O-18", "N", "N", "N"], ["M-4", "M-1", "M-3", "P-3", "M-1", "M-2", "M-3", "O-18", "N", "N", "N"], ["M-3", "M-4", "M-2", "P-1", "M-4", "M-1", "M-1", "O-18", "N", "N", "N"], ["M-3", "M-1", "M-3", "M-1", "M-2", "M-4", "M-3", "O-18", "N", "N", "N"], ["M-1", "M-1", "M-3", "M-1", "M-1", "M-2", "M-2", "O-18", "N", "N", "N"], ["O-18", "O-18", "O-18", "O-18", "O-18", "O-18", "O-18", "O-18", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"]], "bottomSquareData": [["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"]], "topSquareData": [["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"]], "fixedDropData": [["N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N"], ["N", "N", "N", "N", "N", "N", "N", "N", "N"]], "probabilityDropData": [{ "squareTypeStr": "M-1", "precentNumber": 25 }, { "squareTypeStr": "M-2", "precentNumber": 25 }, { "squareTypeStr": "M-3", "precentNumber": 25 }, { "squareTypeStr": "M-4", "precentNumber": 25 }, { "squareTypeStr": "M-5", "precentNumber": 0 }, { "squareTypeStr": "P-1", "precentNumber": 0 }, { "squareTypeStr": "P-2", "precentNumber": 0 }, { "squareTypeStr": "P-3", "precentNumber": 0 }, { "squareTypeStr": "P-4", "precentNumber": 0 }, { "squareTypeStr": "P-5", "precentNumber": 0 }], "targetMatchData": [{ "squareType": 3, "itemType": 18, "tootalCount": 40 }], "levelCategory": 0, "haveNewObstce": 1, "guideIndex": 11, "is_backend": 0 }, "LEVEL_STEEPS": 23, "STARTGUIDE_TYPE": 9, "EVENT_TYPE": 6 }, "props": { "2": 9, "3": 6, "4": 6 }, "event_type": 6, "clock_info": { "clock_days": 1, "progress": { "task_id": 2, "reward_type": 1, "reward": 500, "need": 5, "total": 7, "current": 2, "get_status": 0 }, "task_list": [{ "task_id": "2", "reward_type": 1, "reward": 500, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "3", "reward_type": 2, "reward": 5, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "4", "reward_type": 3, "reward": 3, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "5", "reward_type": 4, "reward": 3, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "6", "reward_type": 1, "reward": 1000, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "7", "reward_type": 2, "reward": 5, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "8", "reward_type": 1, "reward": 500, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "9", "reward_type": 3, "reward": 3, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "10", "reward_type": 4, "reward": 3, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "11", "reward_type": 1, "reward": 1000, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "12", "reward_type": 2, "reward": 5, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "13", "reward_type": 1, "reward": 500, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "14", "reward_type": 3, "reward": 3, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "15", "reward_type": 4, "reward": 3, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "16", "reward_type": 1, "reward": 1000, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "17", "reward_type": 2, "reward": 5, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "18", "reward_type": 1, "reward": 500, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "19", "reward_type": 3, "reward": 3, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "20", "reward_type": 4, "reward": 3, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "21", "reward_type": 1, "reward": 1000, "need": 5, "total": 7, "current": 2, "get_status": 0 }, { "task_id": "22", "reward_type": 2, "reward": 5, "need": 8, "total": 10, "current": 2, "get_status": 0 }, { "task_id": "23", "reward_type": 1, "reward": 500, "need": 8, "total": 10, "current": 2, "get_status": 0 }, { "task_id": "24", "reward_type": 3, "reward": 3, "need": 8, "total": 10, "current": 2, "get_status": 0 }, { "task_id": "25", "reward_type": 4, "reward": 3, "need": 18, "total": 20, "current": 2, "get_status": 0 }, { "task_id": "26", "reward_type": 1, "reward": 1000, "need": 8, "total": 10, "current": 2, "get_status": 0 }, { "task_id": "27", "reward_type": 2, "reward": 5, "need": 38, "total": 40, "current": 2, "get_status": 0 }, { "task_id": "28", "reward_type": 3, "reward": 3, "need": 48, "total": 50, "current": 2, "get_status": 0 }, { "task_id": "29", "reward_type": 4, "reward": 3, "need": 98, "total": 100, "current": 2, "get_status": 0 }, { "task_id": "30", "reward_type": 1, "reward": 1000000, "need": 98, "total": 100, "current": 2, "get_status": 0 }], "yes_clock_data": {} }, "travel": { "cash_balance": 3568, "gold_balance": 55247, "props": { "2": 9, "3": 6, "4": 6 }, "traval_location_info": { "location": 5, "current": 1, "total": 9, "need": 8, "need_total": 29, "now": 21, "xizang": 474, "split_list": [{ "end": 554, "per": 0.003 }, { "end": 624, "per": 0.002 }, { "end": 844, "per": 0.001 }, { "end": 4844, "per": 0.0001 }] }, "update_flag": false, "cash": 0, "money": 0, "cash_before": 0.012, "cash_after": 0.012, "travel_cash_info": { "need": 4, "percent": 0.014 }, "time": "2023/10/24" }, "travel_reward_info": { "gold": 0, "cash": 0 }, "red_flag": 0, "force_video": false } }

        // if (cc.sys.isBrowser) {
            MatchGameData.gameLevel++;
        // }
        HttpHelper.getInstance().wxRequestGet(`/dispel/barrierOver?gold=${e.step}&isTg=1`, (d) => {
            console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',d)
            let result = d;
        // HttpHelper.getInstance().httpGet(`/dispel/barrierOver?gold=${e.step}&isTg=1`, (d) => {
        //     let result = d.result;
            MatchGameData.gameLevel = result.gameLevel;
            MatchGameData.setPropInfo(result.props);
            PeripheralSystemDataMgr.setRewardCash(result.gold);
            PeripheralSystemDataMgr.setRewardGold(result.gold);

            PlayerDataSys.gold_balance =  result.gold;
            NativeUtils.report2('level_win', { level: result.gameLevel,step_leave:e.step });
            NativeUtils.userSet({level_last: result.gameLevel})
            t.runWith(d);
        }, (err) => {
        })//dispel/propsSync

        // debugger
        // HttpHandler.create(RequestType.MatchGameSubMit, t, a).setRequestData(e).handleRequest();
    }
    matchGameVideo(e, t, a) {
        // var d = { "code": 1, "message": "", "data": { gold: 100, cash: 100, props: { "2": 9, "3": 6, "4": 6 }, travel_reward_info: { "gold": 0, "cash": 0 } } }
        // t.runWith(d);
        // HttpHandler.create(RequestType.MatchGameVideo, t, a).setRequestData(e).handleRequest();
    }
    useProp(e, t, a) {
        // var d = { "code": 1, "message": "", "data": { props: { "2": 0, "3": 0, "4": 0 } } }
        // t.runWith(d);
        // HttpHandler.create(RequestType.UseProp, t, a).setRequestData(e).handleRequest();
        HttpHelper.getInstance().wxRequestGet(`/dispel/propsSync?id=${e.prop}&increase=-1`, (d) => {
            console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',d)
            let result = d;
        // HttpHelper.getInstance().httpGet(`/dispel/propsSync?id=${e.prop}&increase=-1`, (d) => {
        //     let result = d.result;
            MatchGameData.setPropInfo(result.props);
            t.runWith(d);
        }, (err) => {
        })

        NativeUtils.report2("skill_use",{
            level_id: MatchGameData.gameLevel,
            skill_name: e.prop
        })
    }

    addProp(e, t, a) {
        // var d = { "code": 1, "message": "", "data": { props: { "2": 0, "3": 0, "4": 0 } } }
        // t.runWith(d);
        // HttpHandler.create(RequestType.UseProp, t, a).setRequestData(e).handleRequest();
        HttpHelper.getInstance().wxRequestGet(`/dispel/propsSync?id=${e.prop}&increase=${e.count}`, (d) => {
            console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',d)
            let result = d;
        // HttpHelper.getInstance().httpGet(`/dispel/propsSync?id=${e.prop}&increase=${e.count}`, (d) => {
        //     let result = d.result;
            MatchGameData.setPropInfo(result.props);
            t.runWith(d);

            NativeUtils.report2("skill_video",{
                level_id: MatchGameData.gameLevel,
                skill_name: e.prop
            })
        }, (err) => {
        })

    }

    adConfig(t1, a) {
        // console.log("请求adconfig");
        // HttpHelper.getInstance().httpGet(`/game/backstage/config`, t => {
        //     console.log('请求adconfig返回');
        //     if (t && 0 == t.code && t.result) {
        //         let str = JSON.stringify(t.result);
        //         for(let i = 0;i < str.split("").length; i+= 200){
        //             console.log("4444444"  + str.slice(i,i+ 200));
        //         }
        //         t1.runWith(t.result);
        //     }
        // }, e => {
        //     console.error("获取广告配置数据失败", e);
        // });
    }

    gameConfig(t1, a) {
        // console.log("请求gameConfig");
        // HttpHelper.getInstance().httpGet(`/dispel/config`, t => {
        //     console.log('请求gameConfig返回');
        //     if (t && 0 == t.code && t.result) {
        //         t1.runWith(t.result);
        //     }
        // }, e => {
        //     console.error("获取广告配置数据失败", e);
        // });
    }

    storeConsume(t1, id) {
        // console.log("请求storeConsume");
        // HttpHelper.getInstance().httpGet(`/dispel/storeConsume?storeId=` + id, t => {
        //     console.log('请求storeConsume返回');
        //     // if (t && 0 == t.code && t.result) {
        //         t1.runWith(t);
        //     // }
        // }, e => {
        //     console.error("获取广告配置数据失败", JSON.stringify(e));
        //     PageMgr.showPage("TravelToastPage", {
        //         text: e.errorMsg || e.errorMessage
        //     });
        // });
    }
}


export default new GameService();
